home *** CD-ROM | disk | FTP | other *** search
/ Eagles Nest BBS 8 / Eagles_Nest_Mac_Collection_Disc_8.TOAST / Developer Tools⁄Additions / InsideBa1994 / InsideBasic-94 / IB 94 / Speech Mgr / SpeechDialog.MAIN < prev    next >
Text File  |  1993-09-22  |  3KB  |  112 lines

  1.  
  2. ' FILE: SPEECHDIALOG.MAIN
  3. '______________________________________________
  4. ' Speech Manager Demo 3 ©1993 Ariel Publishing
  5. '                             by Raoul Watson
  6. '______________________________________________
  7. WINDOW OFF : COORDINATE WINDOW : WIDTH -2
  8. COMPILE 1,8
  9.  
  10. GLOBALS "SPEECH2.GLBL"
  11. END GLOBALS
  12. INCLUDE "SPEECH.TLBX"
  13.  
  14. DIM mystring$
  15. DIM Malechan&,Femalechan&                           'the channels
  16. DIM malename$,femalename$
  17.  
  18. ' calculate the length of the
  19. ' VoiceDescription record
  20. infolength&=@infolength&-@VoiceDescription
  21.  
  22. WINDOW 1,"Speech Dialog Test"
  23. TEXT 4,9,,8
  24.  
  25. IF SYSTEM(_sysVers)< 605 THEN PRINT "Requires System 6.05 or >.":STOP
  26.  
  27. Result = FN GESTALT(_"ttsc")
  28. LONG IF (Result AND 1)
  29.   PRINT "Text To Speech Component present and ready."
  30.   PRINT "SpeechMgr version";FN SpeechManagerVersion/256
  31. XELSE
  32.   PRINT "Sorry, Text To Speech Component not available.":STOP
  33. END IF
  34.  
  35. OSErr=FN CountVoices(@numVoices)
  36.  
  37. LONG IF OSErr=0
  38.   PRINT "There are";numVoices;"voices available."
  39. XELSE
  40.   PRINT "CountVoices OSErr=";OSErr:STOP
  41. END IF
  42.  
  43. ' Here we use the default system voice
  44.  
  45. mystring$="Welcome to Inside BASIC!"
  46. OSErr=FN SpeakString(@mystring$)
  47.  
  48. ' While the default voice is speaking
  49. ' asynchronously, we search for two
  50. ' voices having male and female attributes
  51. MaleFound=0
  52. FemaleFound=0
  53. FOR i=1 TO numVoices
  54.   OSErr = FN GetIndVoice(i,@VoiceSpec)
  55.   LONG IF OSErr=_noErr
  56.     OSErr = FN GetVoiceDescription(@VoiceSpec,@VoiceDescription,infolength&)
  57.     LONG IF OSErr=_noErr
  58.       ' if found male or female, assign a channel
  59.       IF gender =_kMale   THEN GOSUB "getMVoice"
  60.       IF gender =_kFemale THEN GOSUB "getFVoice"
  61.       ' check if we have found two voices
  62.       IF MaleFound AND FemaleFound THEN i=numVoices'terminate loop
  63.     XELSE
  64.       PRINT "OSErr GetVoiceDescription =";OSErr:STOP
  65.     END IF
  66.   XELSE
  67.     PRINT "OSErr GetIndVoice =";OSErr:STOP
  68.   END IF
  69. NEXT i
  70.  
  71. ' Wait until the first phrase is finished
  72. WHILE FN SpeechBusy
  73. WEND
  74.  
  75. ' now conduct some dialog
  76. mystring$="Hello "+femalename$+". It is good to see you."
  77. OSErr=FN SpeakText(Malechan&,@mystring$+1,LEN(mystring$))
  78. WHILE FN SpeechBusy:WEND
  79.  
  80. mystring$=Malename$+"I haven't seen you in ages!"
  81. OSErr=FN SpeakText(Femalechan&,@mystring$+1,LEN(mystring$))
  82. WHILE FN SpeechBusy:WEND
  83.  
  84. mystring$="Well, you know, work, wife, kids, sure keep you busy."
  85. OSErr=FN SpeakText(Malechan&,@mystring$+1,LEN(mystring$))
  86. WHILE FN SpeechBusy:WEND
  87.  
  88. mystring$="I know exactly what you mean!"
  89. OSErr=FN SpeakText(Femalechan&,@mystring$+1,LEN(mystring$))
  90. WHILE FN SpeechBusy:WEND
  91.  
  92. IF Malechan& THEN OSErr=FN DisposeSpeechChannel(Malechan&)
  93. IF Femalechan& THEN OSErr=FN DisposeSpeechChannel(Femalechan&)
  94. END
  95.  
  96. "getMVoice"
  97. IF MaleFound THEN RETURN                            'we already have a male voice
  98. malename$=voiceName$
  99. OSErr=FN NewSpeechChannel(@VoiceSpec,@Malechan&)
  100. IF OSErr THEN PRINT "OSErr NewSpeechChannel =";OSErr:STOP
  101. MaleFound=_zTrue
  102. RETURN
  103.  
  104. "getFVoice"
  105. IF FemaleFound THEN RETURN                          'we already have a female voice
  106. femalename$=voiceName$
  107. OSErr=FN NewSpeechChannel(@VoiceSpec,@Femalechan&)
  108. IF OSErr THEN PRINT "OSErr NewSpeechChannel =";OSErr:STOP
  109. FemaleFound=_zTrue
  110. RETURN
  111.  
  112.